package org.ysu.shoeShopping.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.ysu.shoeShopping.entity.Admins;
import org.ysu.shoeShopping.entity.Orders;
import org.ysu.shoeShopping.service.AdminsService;
import org.ysu.shoeShopping.utils.Result;

import javax.annotation.Resource;
import java.util.List;

/**
 * 后台用户表(Admins)表控制层
 *
 * @author makejava
 * @since 2025-09-13 14:51:42
 */
@RestController
@RequestMapping("admins")
public class AdminsController {
    /**
     * 服务对象
     */
    @Autowired
    private AdminsService adminsService;


    @PostMapping("/login")
    public Result<String> login(@RequestBody Admins admins){
        Admins admins1=adminsService.findByAccountAndApwd(admins.getAcount(),admins.getApwd());
        if (admins1 != null)
        {
            return Result.success("登录成功！");
        }else {
            return  Result.fail("100","登录失败！！");
        }
    }

    @PostMapping("/register")
    public Result<String>register(@RequestBody Admins admins){
        Admins admins1=adminsService.findByAccount(admins.getAcount());
        if (admins1 != null)
        {
            return Result.fail("101","账号已存在！！");
        }else {
            adminsService.insert(admins);
            return  Result.success("注册成功");
        }
    }
@GetMapping("all")
    public Result <List<Admins>>findAdminsAll()
{

    try {
        List<Admins>admins=this.adminsService.findAdminsAll();
        return Result.success(admins);
    }
    catch (Exception e)
    {
        return Result.fail("500","查找失败");
    }
}

}

